<?php
namespace  app\middleware;

use Closure;

class Token{
    public  function handle($request ,\Closure $next){
        $uid=$request->post('uid');
        $token=$request->header('token');
         if (empty($token)) {
            return returnFail(21000,"token不能为空");
        }
        $redis=linkRedis(6);
        $redisTokenJson= $redis->get("partner_token_".$uid);
        if (empty($redisTokenJson)) {
             return returnFail(21001,"token已过期,请重新登录77");
        }
        $newredisTokenRes=json_decode($redisTokenJson,true);
        if($token!=$newredisTokenRes['token']){
            return returnFail(21002,'token已过期,请重新登录88');
        }
        $redis->set("partner_token_".$uid,json_encode(['token'=>$token,
            'expiretime'=>time()+259200]),259000);
        return $next($request);
    }
}